/**
 * (c) Copyright Ascensio System SIA 2025
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.hulman.oms.office.service;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.hulman.oms.bean.OnlyOffice;
import com.hulman.oms.service.OnlyOfficeService;
import com.onlyoffice.manager.security.JwtManager;
import com.onlyoffice.manager.settings.SettingsManager;
import com.onlyoffice.model.documenteditor.Callback;
import com.onlyoffice.service.documenteditor.callback.DefaultCallbackService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

@Component
@Slf4j
public class CallbackServiceImpl extends DefaultCallbackService
{
    @Autowired
    private OnlyOfficeService onlyOfficeService;

    public CallbackServiceImpl(final JwtManager jwtManager, final SettingsManager settingsManager)
    {
        super(jwtManager, settingsManager);
    }

    @Override
    public void handlerEditing(final Callback callback, final String fileId) throws Exception
    {
        log.info("Editing file id:{}", fileId);
    }

    @Override
    public void handlerSave(final Callback callback, final String fileId) throws Exception
    {
        log.info("Saving file id:{}", fileId);
        String fileUrl = callback.getUrl();
        log.info("file url:{}", fileUrl);
        onlyOfficeService.update(fileId, fileUrl);
    }
}
